﻿using System.Windows;
using System.Windows.Documents;

namespace Thinktecture.UIAnnotations.Behaviors
{
    public class CueBannerAdornerFactoryBehavior : AdornerFactoryBehavior
    {
        protected override Adorner CreateAdorner()
        {
            var adorner = new CueBannerAdorner(this.AssociatedObject);
            adorner.CueBanner = this.CueBannerText;
            return adorner;
        }

        #region CueBannerText

        public static readonly DependencyProperty CueBannerTextProperty =
            DependencyProperty.Register("CueBannerText", typeof(string), typeof(CueBannerAdornerFactoryBehavior), new UIPropertyMetadata("", OnCueBannerTextPropertyChanged));
        public string CueBannerText { get { return (string)GetValue(CueBannerTextProperty); } set { SetValue(CueBannerTextProperty, value); } }

        private static void OnCueBannerTextPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ((CueBannerAdornerFactoryBehavior)sender).OnCueBannerTextChanged(sender, e);
        }

        private void OnCueBannerTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.Adorner != null && e.NewValue != null)
                ((CueBannerAdorner)this.Adorner).CueBanner = e.NewValue.ToString();
        }

        #endregion
        
    }
}
